From bd4d15fe1e375e8033c0c6c74dd491ce9569d370 Mon Sep 17 00:00:00 2001 From: Sondre Lefsaker Date: Sun, 3 May 2015 00:49:58 +0200 Subject: [PATCH] Cleanup tests - favor more explicit expected result instead of using helper functions --- tests/test_cargo_rustc.rs | 61 +++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/tests/test_cargo_rustc.rs b/tests/test_cargo_rustc.rs index 1ead1a31d..21cd75aa9 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/test_cargo_rustc.rs @@ -1,42 +1,18 @@ use std::path::MAIN_SEPARATOR as SEP; -use support::{execs, project, ProjectBuilder}; +use support::{execs, project}; use support::{COMPILING, RUNNING}; use hamcrest::{assert_that}; fn setup() { } -fn verbose_output_for_target(lib: bool, p: &ProjectBuilder) -> String { - let (target, kind) = match lib { - true => ("lib", "lib"), - false => ("main", "bin"), - }; - format!("\ -{compiling} {name} v{version} ({url}) -{running} `rustc src{sep}{target}.rs --crate-name {name} --crate-type {kind} -g \ - --out-dir {dir}{sep}target{sep}debug \ - --emit=dep-info,link \ - -L dependency={dir}{sep}target{sep}debug \ - -L dependency={dir}{sep}target{sep}debug{sep}deps` -", - running = RUNNING, compiling = COMPILING, sep = SEP, - dir = p.root().display(), url = p.url(), - target = target, kind = kind, - name = "foo", version = "0.0.1") -} - -fn verbose_output_for_target_with_args(lib: bool, p: &ProjectBuilder, args: &str) -> String { - verbose_output_for_target(lib, p).replace(" -g ", &format!(" -g {} ", args)) -} - test!(build_lib_for_foo { let p = project("foo") .file("Cargo.toml", r#" [package] - name = "foo" version = "0.0.1" - authors = ["wycats@example.com"] + authors = [] "#) .file("src/main.rs", r#" fn main() {} @@ -46,17 +22,25 @@ test!(build_lib_for_foo { assert_that(p.cargo_process("rustc").arg("--lib").arg("-v"), execs() .with_status(0) - .with_stdout(verbose_output_for_target(true, &p))); + .with_stdout(format!("\ +{compiling} foo v0.0.1 ({url}) +{running} `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \ + --out-dir {dir}{sep}target{sep}debug \ + --emit=dep-info,link \ + -L dependency={dir}{sep}target{sep}debug \ + -L dependency={dir}{sep}target{sep}debug{sep}deps` +", + running = RUNNING, compiling = COMPILING, sep = SEP, + dir = p.root().display(), url = p.url()))); }); test!(build_lib_and_allow_unstable_options { let p = project("foo") .file("Cargo.toml", r#" [package] - name = "foo" version = "0.0.1" - authors = ["wycats@example.com"] + authors = [] "#) .file("src/main.rs", r#" fn main() {} @@ -67,18 +51,26 @@ test!(build_lib_and_allow_unstable_options { .arg("--").arg("-Z").arg("unstable-options"), execs() .with_status(0) - .with_stdout(verbose_output_for_target_with_args(true, &p, - "-Z unstable-options"))); + .with_stdout(format!("\ +{compiling} foo v0.0.1 ({url}) +{running} `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \ + -Z unstable-options \ + --out-dir {dir}{sep}target{sep}debug \ + --emit=dep-info,link \ + -L dependency={dir}{sep}target{sep}debug \ + -L dependency={dir}{sep}target{sep}debug{sep}deps` +", + running = RUNNING, compiling = COMPILING, sep = SEP, + dir = p.root().display(), url = p.url()))) }); test!(build_main_and_allow_unstable_options { let p = project("foo") .file("Cargo.toml", r#" [package] - name = "foo" version = "0.0.1" - authors = ["wycats@example.com"] + authors = [] "#) .file("src/main.rs", r#" fn main() {} @@ -113,10 +105,9 @@ test!(fails_when_trying_to_build_main_and_lib_with_args { let p = project("foo") .file("Cargo.toml", r#" [package] - name = "foo" version = "0.0.1" - authors = ["wycats@example.com"] + authors = [] "#) .file("src/main.rs", r#" fn main() {} -- 2.30.2